<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
/**
 * 验证请求的md5值
 */
/**
 * [返回需要输出的带状态值的Json字符串]
 * @param [string] $code [状态码：0失败，1成功]
 * @param [string] $msg    [需要返回的数据]
 */

function error($msg){
    $result = array(
        "code"=>'0',
        "msg"=>$msg
    );
    echo json_encode($result);
    exit;
}

function echoJson($code, $msg) {
    if (is_string($msg)) {
        $arr = array("code" => $code, "msg" => $msg);
    } else {
        $arr = array("code" => $code, "msg" => $msg);
    }
    echo json_encode($arr, JSON_UNESCAPED_UNICODE);
    exit;
}

/**
 *
 * 把字符串转换成json数组（错误返回空数组）
 * $jsonStr json字符串
 *
 */
function strToJsonArr($jsonStr) {
    !empty($jsonStr) ? $jsonArr = json_decode($jsonStr, true) : $jsonArr = [];
    is_array($jsonArr) ? "" : $jsonArr = [];
    return $jsonArr;
}

/**
 *
 * 把json转换成字符串
 * $jsonStr json字符串
 *
 */
function jsonToStr($Str) {
    return json_encode($Str, JSON_UNESCAPED_UNICODE);
}

function getParameter($str){
    return $_GET[$str];
}

function logout($str){
    $status = true;
    if($status){
        var_dump(json_encode($str,true));
        exit();
    }

}


function gettime(){
   return date("YmdHisa");
}

function dateFormat($default="Y-m-d H:i:s"){
    return date($default);
}